package miaofusdk

import (
	"encoding/json"
	"fmt"
)

func (s *SrvDataCenterManager) ServiceOrderList(page, rows int, search_order_type, search_order_value, search_order_status, plugin_name string) (RespServiceMarketOrders, error) {
	resp := RespServiceMarketOrders{}
	http_request := s.GetPost(s.GetUrl() + "/plugin/order_list")
	http_request.Param("page", fmt.Sprintf("%d", page))
	http_request.Param("rows", fmt.Sprintf("%d", rows))
	http_request.Param("search_order_type", search_order_type)
	http_request.Param("search_order_value", search_order_value)
	http_request.Param("search_order_status", search_order_status)
	http_request.Param("plugin_name", plugin_name)
	if v, err := http_request.Bytes(); err != nil {
		return resp, err
	} else if err := json.Unmarshal(v, &resp); err != nil {
		return resp, err
	} else {
		return resp, nil
	}
}

func (s *SrvDataCenterManager) ServiceOrderDetailList(page, rows int, order_id, search_order_type, search_order_value, search_order_status string) (RespServiceMarketOrderDetails, error) {
	resp := RespServiceMarketOrderDetails{}
	http_request := s.GetPost(s.GetUrl() + "/plugin/order_detail_list")
	http_request.Param("page", fmt.Sprintf("%d", page))
	http_request.Param("rows", fmt.Sprintf("%d", rows))
	http_request.Param("order_id", order_id)
	http_request.Param("search_order_type", search_order_type)
	http_request.Param("search_order_value", search_order_value)
	http_request.Param("search_order_status", search_order_status)
	if v, err := http_request.Bytes(); err != nil {
		return resp, err
	} else if err := json.Unmarshal(v, &resp); err != nil {
		return resp, err
	} else {
		return resp, nil
	}
}

func (s *SrvDataCenterManager) ServerOrderStatsLst(page, rows int, by, plugin_name, start_time, end_time string) (RespServiceOrderStatss, error) {
	resp := RespServiceOrderStatss{}
	http_request := s.GetPost(s.GetUrl() + "/plugin/order_stats")
	http_request.Param("page", fmt.Sprintf("%d", page))
	http_request.Param("rows", fmt.Sprintf("%d", rows))
	http_request.Param("group_by", by)
	http_request.Param("plugin_name", plugin_name)
	http_request.Param("start_time", start_time)
	http_request.Param("end_time", end_time)

	if v, err := http_request.Bytes(); err != nil {
		return resp, err
	} else if err := json.Unmarshal(v, &resp); err != nil {
		return resp, err
	} else {
		return resp, nil
	}
}

func (s *SrvDataCenterManager) KoubeiItemList(page, rows int, search_order_type, search_order_value, status string) (RespAliItems, error) {
	resp := RespAliItems{}
	http_request := s.GetPost(s.GetUrl() + "/koubei_item/list")
	http_request.Param("page", fmt.Sprintf("%d", page))
	http_request.Param("rows", fmt.Sprintf("%d", rows))
	http_request.Param(search_order_type, search_order_value)
	http_request.Param("status", status)
	if v, err := http_request.Bytes(); err != nil {
		return resp, err
	} else if err := json.Unmarshal(v, &resp); err != nil {
		return resp, err
	} else {
		return resp, nil
	}
}

type KoubeiItemOrderBean struct {
	Id         int    `json:"id"`
	UserId     string `json:"user_id"`
	Amount     string `json:"amount"`
	Status     string `json:"status"`
	OutBizNo   string `json:"out_biz_no"`
	OrderNo    string `json:"order_no"`
	TransNo    string `json:"trans_no"`
	NotifyTime string `json:"notify_time"`
	Memo       string `json:"memo"`
	ItemId     string `json:"item_id"`
	VoucherId  string `json:"voucher_id"`
	ItemName   string `json:"item_name"`
	ShopName   string `json:"shop_name"`
	ShopId     string `json:"shop_id"` //口碑门店号
}

type RespKoubeiItemOrderBean struct {
	Response
	Data KoubeiItemOrderBean `json:"data,omitempty"`
}

type RespKoubeiItemOrderBeans struct {
	Response
	Page       int                   `json:"page,string"`
	Rows       int                   `json:"rows,string"`
	TotalCount int                   `json:"total_count,string"`
	TotalPage  int                   `json:"total_page,string"`
	List       []KoubeiItemOrderBean `json:"list,omitempty,string"`
}

func (s *SrvDataCenterManager) KoubeiOrderList(page, rows int, user_id, shop_name, order_no, item_id, item_name, start_time, end_time, status, shop_id string) (RespKoubeiItemOrderBeans, error) {
	resp := RespKoubeiItemOrderBeans{}
	http_request := s.GetPost(s.GetUrl() + "/koubei_item/order_list")
	http_request.Param("page", fmt.Sprintf("%d", page))
	http_request.Param("rows", fmt.Sprintf("%d", rows))
	http_request.Param("user_id", user_id)
	http_request.Param("shop_name", shop_name)
	http_request.Param("order_no", order_no)
	http_request.Param("item_id", item_id)
	http_request.Param("item_name", item_name)
	http_request.Param("start_time", start_time)
	http_request.Param("end_time", end_time)
	http_request.Param("status", status)
	http_request.Param("shop_id", shop_id)
	if v, err := http_request.Bytes(); err != nil {
		return resp, err
	} else if err := json.Unmarshal(v, &resp); err != nil {
		return resp, err
	} else {
		return resp, nil
	}
}

type KoubeiItemOrderStats struct {
	SettleAmount string `json:"settle_amount"`
	SettleCount  string `json:"settle_count"`
	RefundAmount string `json:"refund_amount"`
	RefundCount  string `json:"refund_count"`
	Status       string `json:"status,omitempty"`
	ItemId       string `json:"item_id,omitempty"`
	ItemName     string `json:"item_name,omitempty"`
	Day          string `json:"day,omitempty"`
}

type KoubeiItemOrderStatsNew struct {
	ReceiptAmount string `json:"receipt_amount"`
	ReceiptCount  string `json:"receipt_count"`
	CurrentAmount string `json:"current_amount"`
	Status        string `json:"status,omitempty"`
	ItemId        string `json:"item_id,omitempty"`
	ItemName      string `json:"item_name,omitempty"`
	Day           string `json:"day,omitempty"`
}

type RespKoubeiItemOrderStats struct {
	Response
	Data KoubeiItemOrderStats `json:"data,omitempty"`
}

type RespKoubeiItemOrderStatsNew struct {
	Response
	Data KoubeiItemOrderStatsNew `json:"data,omitempty"`
}

type RespKoubeiItemOrderStatsExt struct {
	Response
	ALL  KoubeiItemOrderStats   `json:"all,omitempty"`
	List []KoubeiItemOrderStats `json:"list,omitempty"`
}

type RespKoubeiItemOrderStatsExtNew struct {
	Response
	ALL  KoubeiItemOrderStatsNew   `json:"all,omitempty"`
	List []KoubeiItemOrderStatsNew `json:"list,omitempty"`
}

func (s *SrvDataCenterManager) KoubeiOrderStats(user_id, shop_name, item_id, item_name, start_time, end_time, shop_id string) (RespKoubeiItemOrderStats, error) {
	resp := RespKoubeiItemOrderStats{}
	http_request := s.GetPost(s.GetUrl() + "/koubei_item/order_stats")
	http_request.Param("user_id", user_id)
	http_request.Param("shop_name", shop_name)
	http_request.Param("item_id", item_id)
	http_request.Param("item_name", item_name)
	http_request.Param("start_time", start_time)
	http_request.Param("end_time", end_time)
	http_request.Param("shop_id", shop_id)
	if v, err := http_request.Bytes(); err != nil {
		return resp, err
	} else if err := json.Unmarshal(v, &resp); err != nil {
		return resp, err
	} else {
		return resp, nil
	}
}

type RespKoubeiTicketcodeBeans struct {
	Response
	Page       int                    `json:"page,string"`
	Rows       int                    `json:"rows,string"`
	TotalCount int                    `json:"total_count,string"`
	TotalPage  int                    `json:"total_page,string"`
	List       []KoubeiTicketcodeBean `json:"list,omitempty,string"`
}

type KoubeiTicketcodeBean struct {
	Id                        int    `json:"id"`
	ShopId                    string `json:"shop_id"`
	ShopName                  string `json:"shop_name"`
	StoreCode                 string `json:"store_code"`
	ShopCode                  string `json:"shop_code"`
	OrgCode                   string `json:"org_code"`
	DevId                     string `json:"dev_id"`
	TicketCode                string `json:"ticket_code"`
	ItemName                  string `json:"item_name"`
	ItemId                    string `json:"item_id"`
	OriginalPrice             string `json:"original_price"`
	CurrentPrice              string `json:"current_price"`
	EffectDate                string `json:"effect_date"`
	ExpireDate                string `json:"expire_date"`
	TicketStatus              string `json:"ticket_status"`
	TicketStatusDesc          string `json:"ticket_status_desc"`
	TicketTransId             string `json:"ticket_trans_id"`
	TicketTransType           string `json:"ticket_trans_type"`
	TicketTransCreateTime     string `json:"ticket_trans_create_time"`
	TicketTransLastModifyTime string `json:"ticket_trans_last_modify_time"`
	UseDate                   string `json:"use_date"`
	UseShopId                 string `json:"use_shop_id"`
	UseShopName               string `json:"use_shop_name"`
	ItemMemo                  string `json:"item_memo"`
	BuyerPayAmount            string `json:"buyer_pay_amount"`
	ReceiptAmount             string `json:"receipt_amount"`
	DiscountAmount            string `json:"discount_amount"`
	KoubeiSubsidyAmount       string `json:"koubei_subsidy_amount"`
	InvoiceAmount             string `json:"invoice_amount"`
	BatchNo                   int    `json:"batch_no"`
	OperId                    string `json:"oper_id"`
	RequestId                 string `json:"request_id"`
}
